

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;

public partial class Admin_Ad_AddHospital : System.Web.UI.Page
{
    //Create an Object of Manager which is defined in the namespace SiteManager
    Manager mgr = new Manager(true, "ConnectionString");
    public int id = 0;
    public string path = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
        }
        catch { id = 0; }
        //Label1 will be responsible to show the message whether the User is adding a new
        // User or Editing a Site user.
        ViewState["id"] = id;
        Label1.Font.Bold = true;
        Label1.ForeColor = System.Drawing.Color.Black;
        Label1.Text = id == 0 ? "Add SEO Tags" : "Update SEO Tags";


        if (!IsPostBack)
        {
            //Function called 

            FillCombos(id);


        }
    }

    /// <summary>
    /// this function fills up all the drop downs
    /// </summary>
    /// <param name="id"></param>
    public void FillCombos(int id)
    {


        //   mgr.BindList("select countrycode,countryname from tbl_country", "countryname", "countrycode", combocountryid, "select");
        //   mgr.BindList("select secquestion,sno from tbl_secquestions", "secquestion", "sno", combosecretquestion, "select");
        ////   mgr.BindList("select healthcplan,sno from tbl_healthcplan", "healthcplan", "sno", combohealthplan, "select");
        //    mgr.BindList("select id,name from tbl_InsuranceCompanies", "name", "Id", combohealthplan, "select");
        //Edit a Site Users info
        if (id > 0)
        {
            // Create an Object of Recordset i.e Dataset 
            DataSet ds = mgr.ExecuteQuery("select * from SEO where ID='" + id + "' ", "tbl_usa_hospitals");
            if (ds.Tables[0].Rows.Count > 0)
            {
                
                    txtPageName.Text = ds.Tables[0].Rows[0]["PageName"].ToString();
               
                txtTitle.Text = ds.Tables[0].Rows[0]["Title"].ToString();
                txtDescription.Text = ds.Tables[0].Rows[0]["Description"].ToString();
                txtKeyWords.Text = ds.Tables[0].Rows[0]["KeyWords"].ToString();


            }
            else
            {
                Label2.Visible = true;
                Label2.ForeColor = System.Drawing.Color.Red;
                Label2.Text = "No Records found!!";
                return;
            }
        }
        else
        {
            txtPageName.Text = Request.QueryString["from"].ToString();
           

        }

    }



    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Label2.Text = "";
        //checking for duplicate email when inserting a new record                  
        string sql = "";

        int id = (int)ViewState["id"];


        //Retrieving All the Values of Forms in the Variables

        string Title = txtTitle.Text.Replace("'", "''").Trim();
        string Description = txtDescription.Text.Replace("'", "''").Trim();
        string KeyWords = txtKeyWords.Text.Replace("'", "''").Trim();

        DateTime tregdt = DateTime.Now;


        string sqlQuery = "";
        if (id > 0)
        {

            //Update Site User Query
            sqlQuery = "UPDATE [SEo] SET [Title] = '" + Title + "',"; //"[Country]='" + Country + "' ";
            sqlQuery += "[Description]='" + Description + "',[KeyWords] = '" + KeyWords + "' where Id=" + id;
            // Response.Write("query" + sqlQuery);

        }
        else
        {
            if (Request.QueryString["from"] == "DentistProfile")
            {
                DataSet ds1 = mgr.ExecuteQuery("select * from SEO where ID='" + id + "' and [Type] = 'DentistProfile' ", "SEO");
                if (ds1.Tables[0].Rows.Count == 0)
                {//Update Site User Query
                    sqlQuery = "INSERT INTO [SEO] ([PageName],[PageNumber],[Title],[Description],[KeyWords],[Type]) ";
                    sqlQuery += "VALUES ('" + Request.QueryString["dentistid"].ToString() + "','1','" + Title + "','" + Description + "','" + KeyWords + "','" + Request.QueryString["from"].ToString() + "')";
                }

            }
            if (Request.QueryString["from"] == "DoctorProfile")
            {
                DataSet ds1 = mgr.ExecuteQuery("select * from SEO where ID='" + id + "' and [Type] = 'DoctorProfile' ", "SEO");
                if (ds1.Tables[0].Rows.Count == 0)
                {//Update Site User Query
                    sqlQuery = "INSERT INTO [SEO] ([PageName],[PageNumber],[Title],[Description],[KeyWords],[Type]) ";
                    sqlQuery += "VALUES ('" + Request.QueryString["DoctorID"].ToString() + "','1','" + Title + "','" + Description + "','" + KeyWords + "','" + Request.QueryString["from"].ToString() + "')";
                }

            }
        }
        //else
        //{
        //    //Insert Site User Query
        //    sqlQuery = "INSERT INTO [tbl_usa_hospitals] ([Hospital_Name],[Country],[Phone],[Fax],[Website],[Email],[About],[Map],[Address],[latest],[featured],[tophospital]) values('";
        //    sqlQuery += hospitalname + "','USA','" + Phone + "','" + Fax + "','" + Website + "','" + Email + "','" + About + "','','" + address + "','" + latest.ToString() + "',";
        //    sqlQuery += " '" + featured.ToString() + "','" + tophospital.ToString() + "')";
        //    Response.Write("New User Added Successfully !!");
        //}
        try
        {
            mgr.ExecuteQuery(sqlQuery);
            //If Query is successfull the User will be redirected to the main page
            if (Request.QueryString["from"].ToString() == "Page")
            {
                Response.Redirect("Ad_ManageSEO_Pages.aspx?type=Page");
            }
            if (Request.QueryString["from"].ToString() == "DoctorCategory")
            {
                Response.Redirect("Ad_ManageSEO_Pages.aspx?type=DoctorCategory");
            }
            if (Request.QueryString["from"].ToString() == "DoctorSpeciality")
            {
                Response.Redirect("Ad_ManageSEO_Pages.aspx?type=DoctorSpeciality");
            }
            if (Request.QueryString["from"].ToString() == "DentistSpeciality")
            {
                Response.Redirect("Ad_ManageSEO_Pages.aspx?type=DentistSpeciality");
            }
            if (Request.QueryString["from"].ToString() == "DentistProfile")
            {
                Response.Redirect("Ad_ManageDentitsSEO.aspx");
            }
            if (Request.QueryString["from"].ToString() == "DoctorProfile")
            {
                Response.Redirect("Ad_ManageDoctorsSEO.aspx");
            }
            
        }
        // If any Exception occurs like if a System throws any exception at the 
        // time of running a query than it will be caught by the Mother class of 
        // Exception i.e 'Throwable'for which object has been created with a name of 'es'.
        catch (Exception es)
        {
            Response.Write(es.ToString());
            Label2.Visible = true;
            Label2.Font.Bold = true;
            Label2.ForeColor = System.Drawing.Color.Red;
            Label2.Text = es.ToString();
        }

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        int id = (int)ViewState["id"];
        //If Cancel button is clicked than the user will be redirected to the main page.
        if (id > 0)
        {
            if (Request.QueryString["from"].ToString() == "Page")
            {
                Response.Redirect("Ad_ManageSEO_Pages.aspx?type=Page");
            }
            if (Request.QueryString["from"].ToString() == "DoctorCategory")
            {
                Response.Redirect("Ad_ManageSEO_Pages.aspx?type=DoctorCategory");
            }
            if (Request.QueryString["from"].ToString() == "DoctorSpeciality")
            {
                Response.Redirect("Ad_ManageSEO_Pages.aspx?type=DoctorSpeciality");
            }
            if (Request.QueryString["from"].ToString() == "DentistSpeciality")
            {
                Response.Redirect("Ad_ManageSEO_Pages.aspx?type=DentistSpeciality");
            }
            if (Request.QueryString["from"].ToString() == "DentistProfile")
            {
                Response.Redirect("Ad_ManageDentitsSEO.aspx");
            }
            if (Request.QueryString["from"].ToString() == "DoctorProfile")
            {
                Response.Redirect("Ad_ManageDoctorsSEO.aspx");
            }
        }
        else
        {
            Response.Redirect("ADadminAccess.aspx");
        }
    }
}
